import React, { Component } from 'react'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'

import Root from './index.js'
import reducers from './redux/reducer/index'
import { middlewares } from './redux/store/index'
export const store = createStore(reducers, applyMiddleware(...middlewares))

// 热更新
// import CodePush from 'react-native-code-push'
// 启动闪屏
// import SplashScreen from 'react-native-splash-screen'
export default class App extends Component {
  componentDidMount() {
    // this.syncImmediate()
    // SplashScreen.hide()
  }

  // syncImmediate = () => {
  //   CodePush.sync(
  //     {
  //       //启动模式三种：ON_NEXT_RESUME、ON_NEXT_RESTART、IMMEDIATE
  //       // installMode: CodePush.InstallMode.ON_NEXT_RESTART,
  //     },
  //     this.codePushStatusDidChange,
  //     this.codePushDownloadDidProgress
  //   )
  // }

  // codePushDownloadDidProgress = (progress) => {
  //   console.log(progress)
  // }

  // codePushStatusDidChange = (syncStatus) => {
  //   switch (syncStatus) {
  //     case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
  //       console.log('Checking for update.') //正在检查是否有更新
  //       break
  //     case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
  //       console.log('Downloading package.') //有更新包正在下载
  //       break
  //     case CodePush.SyncStatus.AWAITING_USER_ACTION:
  //       console.log('Awaiting user action.')
  //       break
  //     case CodePush.SyncStatus.INSTALLING_UPDATE:
  //       console.log('Installing update.') //更新包下载完成即将被安装
  //       break
  //     case CodePush.SyncStatus.UP_TO_DATE:
  //       console.log('App up to date.') //检查更新没有更新包或者更新完成reset完成
  //       // NativeModuleUtil.hideSplashScreen()
  //       break
  //     case CodePush.SyncStatus.UPDATE_IGNORED: //提示更新后，用户选择了忽视(这只是适用updateDialog时使用)
  //       console.log('Update cancelled by user.')
  //       break
  //     case CodePush.SyncStatus.UPDATE_INSTALLED:
  //       console.log('Update installed and will be applied on restart.') //在INSTALLING_UPDATE之后调用,更新包安装之前，
  //       break
  //     case CodePush.SyncStatus.UNKNOWN_ERROR: //同步操作遇到了一个未知错误。
  //       console.log('An unknown error occurred.')
  //       // NativeModuleUtil.hideSplashScreen()
  //       break
  //   }
  // }

  render() {
    return (
      <Provider store={store}>
        <Root />
      </Provider>
    )
  }
}
